#TOPDIR	:= $(shell /bin/pwd)

#CFLAGS= -Os -fomit-frame-pointer  -DVIDEO_DEBUG

INC_PATH =  -I//opt/wisermind_MPC83xx/powerpc-e300c3-linux/include

CROSS_COMPILE=/opt/wisermind_MPC83xx/bin/powerpc-e300c3-linux-
LIBPATH=/opt/wisermind_MPC83xx/powerpc-e300c3-linux/lib
#CFLAGS= 
#LDFLAGS= -L/opt/wisermind_MPC83xx/powerpc-e300c3-linux/lib -L. $(LIBPATH)/libc.so $(LIBPATH)/libpthread.so 
LDFLAGS= -L/opt/wisermind_MPC83xx/powerpc-e300c3-linux/lib -L.  
#LDFLAGS= -L/usr/lib -L/usr/lib/mysql -L. -lmysqlclient  -lpthread -lc -allow-shlib-undefined
CC = $(CROSS_COMPILE)gcc
CPLUSPLUS = $(CROSS_COMPILE)g++
LD =  $(CROSS_COMPILE)ld

#LDFLAGS += CERPATH

CFLAGS += -DDEBUG -D__Linux__ -g  -mpowerpc -msoft-float

#TOPDIR:=$(shell /bin/pwd)

ifeq ($(strip $(TOPDIR)),)
TOPDIR	:= $(shell /bin/pwd)/..
endif

ifeq ($(strip $(BUILD_MYAPP)), static)
CFLAGS += -DBUILD_STATIC
endif

ifeq ($(strip $(BUILD_MYAPP)), debug)
	CFLAGS += -g -static
else
#CFLAGS += -s
endif

all:libframe.so last

CFLAGS += $(INC_PATH) 	
#CFLAGS += -I$(TOPDIR)/include
CFLAGS += -I$(TOPDIR)/com_inc -I$(TOPDIR)/sim_inc

#SERVEROBJSTEST =netIoMemPool.o CLog.o RoundSeq.o seqMemPool.o systemFun.o Server.o 
SERVEROBJS=framelist.o CLog.o CAsynchIo.o CBaseMainManage.o  CSqlParmer.o pthreadBaseMain.o seqMsgPool.o RoundSeq.o seqMemPool.o systemFunLinux.o  netIoMemPool.o netIoSeq.o GlobalHelper.o GlobalParm.o pthreadNet.o pthreadWork.o ServerMain.o  ServerTest.o netSocketLinux.o co_mem.o

CLIENTOBJS =Client.o

per:
	cp *.h $(TOPDIR)/include 

last:
	cp libframe.so $(TOPDIR)/bin 

libframe.so:serverld.o
	$(CPLUSPLUS) -shared -IPIC serverld.o -o libframe.so $(LDFLAGS) 
#

server:serverld.o
	$(CPLUSPLUS) serverld.o  -o server $(LDFLAGS) && ls -l server
#	$(STRIP)   server

client:clientld.o
	$(CPLUSPLUS) clientld.o  -o client $(LDFLAGS) && ls -l client

serverld.o:$(SERVEROBJS)
	$(LD) $(EXTRA_LDFLAGS) $(LDFLAGS) -r -o $@ $(SERVEROBJS)


clientld.o:$(CLIENTOBJS)
	$(LD) $(EXTRA_LDFLAGS) $(LDFLAGS) -r -o $@ $(CLIENTOBJS)

%.o: %.c
	$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $<

%.o: %.cpp
	$(CPLUSPLUS) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $<


clean:
	-rm -f $(SERVEROBJS) $(CLIENTOBJS) server client *.o *.so
